package de.learnlib.examples;

/* Copyright (C) 2013-2021 TU Dortmund
 * This file is part of LearnLib, http://www.learnlib.de/.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Random;

import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFA;
import de.learnlib.algorithms.lstar.dfa.ClassicLStarDFABuilder;
import de.learnlib.algorithms.rivestschapire.RivestSchapireDFA;
import de.learnlib.algorithms.rivestschapire.RivestSchapireDFABuilder;
import de.learnlib.algorithms.lstar.dfa.ShahbazDFA;
import de.learnlib.algorithms.lstar.dfa.ShahbazDFABuilder;
import de.learnlib.api.algorithm.LearningAlgorithm;
import de.learnlib.api.oracle.MembershipOracle.DFAMembershipOracle;
import de.learnlib.counterexamples.LocalSuffixFinders;
import de.learnlib.datastructure.observationtable.OTUtils;
import de.learnlib.datastructure.observationtable.writer.ObservationTableASCIIWriter;
import de.learnlib.filter.cache.dfa.DFACaches;
import de.learnlib.filter.statistic.oracle.DFACounterOracle;
import de.learnlib.oracle.equivalence.DFARandomWordsEQOracle;
import de.learnlib.oracle.equivalence.DFAWMethodEQOracle;
import de.learnlib.oracle.membership.SimulatorOracle.DFASimulatorOracle;
import de.learnlib.util.Experiment.DFAExperiment;
import de.learnlib.util.statistics.SimpleProfiler;
import net.automatalib.automata.fsa.DFA;
import net.automatalib.automata.fsa.impl.compact.CompactDFA;
import net.automatalib.incremental.dfa.tree.IncrementalDFATreeBuilder;
import net.automatalib.serialization.dot.GraphDOT;
import net.automatalib.serialization.fsm.parser.FSM2DFAParser;
import net.automatalib.util.automata.builders.AutomatonBuilders;
import net.automatalib.util.automata.random.RandomAutomata;
import net.automatalib.visualization.Visualization;
import net.automatalib.words.Alphabet;
import net.automatalib.words.impl.Alphabets;
import de.learnlib.algorithms.discriminationtree.dfa.DTLearnerDFA;
import de.learnlib.algorithms.discriminationtree.dfa.DTLearnerDFABuilder;
import de.learnlib.filter.cache.dfa.DFACacheOracle;
import de.learnlib.filter.cache.dfa.DFACaches;
import net.automatalib.incremental.dfa.tree.IncrementalDFATreeBuilder;
import de.learnlib.oracle.equivalence.DFARandomWordsEQOracle;
import de.learnlib.oracle.equivalence.DFARandomWMethodEQOracle;
import net.automatalib.util.automata.random.RandomAutomata;
/**
 * This example constructs random DFA
 *
 * @author z11panyan
 */
@SuppressWarnings("PMD.SystemPrintln")
public final class RandomDFAConstruct {

    private static final int EXPLORATION_DEPTH = 4;

    private RandomDFAConstruct() {
        // prevent instantiation
    }

    public static void main(String[] args) throws IOException {

        // contruct DFA and alphabet

        Random rand = new Random();
        for(int i = 0; i < 100; i++)
        {
            CompactDFA<Integer> target = constructSUL(rand,20,100);
            recordSUL(rand,target,i);
        }

    }

    /**
     * creates example from Angluin's seminal paper.
     *
     * @return example dfa
     */
    private static CompactDFA<Integer> constructSUL(Random rand, int numInputs, int size) {


        CompactDFA<Integer> randomDfa = RandomAutomata.randomDFA(rand, size, Alphabets.integers(0, numInputs - 1));

        return randomDfa;
    }

    private static void recordSUL(Random rand,CompactDFA<Integer> randomDfa, int index) {
        try {
            PrintWriter out = new PrintWriter("/home/xxxx/model/learnlib/algorithms/active/ttt/src/test/resources/DFA0.4"+randomDfa.size()+"-"+randomDfa.getInputAlphabet().size()+"_"+index+".dfa");//输出的路径和文件名
            out.printf("%d %d %n", randomDfa.size(), randomDfa.getInputAlphabet().size());
            for (int i = 0; i < randomDfa.size(); i++) {
                if(rand.nextInt(100) > 40)
                    out.printf("%d ", 1);
                else
                    out.printf("%d ", 0);
            }
            out.printf("%n");
            for (int i = 0; i < randomDfa.size(); i++) {
                for (int j = 0; j < randomDfa.getInputAlphabet().size(); j++)
                    out.printf("%d ", randomDfa.getTransition(i, j));
                out.printf("%n");
            }
            out.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}

